package com.neu.ui.home;

import com.google.gson.Gson;
import com.neu.bean.Rotation;
import com.neu.bean.WeatherBean;
import com.neu.util.RetrofitClient;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

public class HomeViewModel extends ViewModel {

    private MutableLiveData<Rotation> mRotation;
    private MutableLiveData<WeatherBean> mWeather;
    private Gson gson;
    public HomeViewModel() {
        mRotation = new MutableLiveData<>();
        mWeather = new MutableLiveData<>();
        gson=new Gson();
    }

    public LiveData<Rotation> getRotation() {
        String url="/prod-api/api/rotation/list?pageNum=1&pageSize=8&type=2";
        new RetrofitClient().get(url, new RetrofitClient.BackJson() {
            @Override
            public void success(String json) {
                Rotation rotation=gson.fromJson(json,Rotation.class);
                mRotation.setValue(rotation);
            }
        });

        return mRotation;
    }

    public LiveData<WeatherBean> getWeather() {
        String url="/prod-api/api/common/weather/today";
        new RetrofitClient().get(url, new RetrofitClient.BackJson() {
            @Override
            public void success(String json) {
                WeatherBean bean=gson.fromJson(json,WeatherBean.class);
                mWeather.setValue(bean);
            }
        });

        return mWeather;
    }


}